<?php

namespace frontend\model\order;

use bc\ar\MActiveRecord;

class BindModel extends MActiveRecord
{
	/**
	 * 定义数据表
	 */
	public static function tableName()
	{
		return '{{%order_bind}}'; 
	}
	
	/**
	 * 
	 * @param string $params
	 * @param int $page
	 * @param int $pageSize
	 */
	public function getReportList($params, $page = null, $pageSize = null)
	{
		//select o.goods_name, b.* from bc_order as o left join bc_order_bind as b on o.id = b.order_id
		$ar = $this->find ()->select ( 'bc_order.order_no, bc_order_bind.*' )
		->innerJoin('bc_order', 'bc_order.order_id = bc_order_bind.order_id');
		if ($params)
		{
			$ar->where ( $params );
		}
		if ($page && $pageSize)
		{
			$offset = $this->getOffset ( $page, $pageSize );
			$ar->offset ( $offset )->limit ( $pageSize );
		}
		
               // echo $ar->createCommand()->sql;
                
		if ($this->sort != null)
			$ar->orderBy ( $this->sort );
		return $ar->asArray ()->all ();
	}
        
        public function getTotal()
	{
	   
			return $this->find()->innerJoin('bc_order', 'bc_order.order_id = bc_order_bind.order_id')->count();
	
	}
}